import matplotlib.pyplot as plt


def read_data_from_file(file_path):
    x_values = []
    y_values = []

    with open(file_path, 'r') as file:
        for line in file:
            parts = line.split()
            if len(parts) >= 2:
                x_values.append(float(parts[0]))  # 横轴值
                y_values.append(float(parts[1]))  # 探索覆盖率值
    return x_values, y_values


def plot_data(x, y):
    # plt.figure(figsize=(10, 6))
    plt.plot(x, y, marker='o',markersize=3)
    plt.title('map3-本文方法探索覆盖率',fontsize=30, fontweight='bold')
    plt.xlabel('探索时间(s)',fontsize=17, fontweight='bold')
    plt.ylabel('探索覆盖率 (%)',fontsize=17, fontweight='bold')
    plt.xlim(min(x), max(x))
    plt.ylim(0, 1)  # 假设覆盖率在0到100之间
    plt.grid()
    plt.savefig('map3_本文方法.png')  # 将图像保存为 PNG 文件
    plt.show()  # 显示图像


def main():
    file_path = "img/result/map3/map_3_searchBox_2024-04-06-23_45_51.txt"
    print(file_path)
    x_values, y_values = read_data_from_file(file_path)
    print(x_values, y_values)
    plot_data(x_values, y_values)


if __name__ == "__main__":
    plt.rcParams['font.sans-serif'] = ['SimHei']  # 指定默认字体为黑体
    plt.rcParams['axes.unicode_minus'] = False  # 解决保存图像是负号'-'显示为方块的问题
    main()